package com.pengweiwei.androidzygote.functions.picture;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.pengweiwei.androidzygote.R;
import com.putong35.common.baseactfrag.activity.BaseActivity;
import com.putong35.easyui.picture.browser.constant.Constant;
import com.putong35.easyui.picture.browser.view.PictureBrowserActivity;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/6/8
 */
public class PictureBrowDemoActivity extends BaseActivity {
    private final static String TAG = PictureBrowDemoActivity.class.getSimpleName();
    ArrayList<String> mDataList = new ArrayList<>();

    public static void newInstance(Activity fromActivity) {
        Intent intent = new Intent(fromActivity, PictureBrowDemoActivity.class);
        fromActivity.startActivity(intent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        setSwipeBackEnable(true);

    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.act_picture_bro_demo, null);
        mDataList.add("http://pkicdn.image.alimmdn.com/old/newuploads/8bdaaa6d4e1fbc5e03385ef454f9577e.jpg");
        mDataList.add("http://pkicdn.image.alimmdn.com/old/newuploads/0b79e02a47d57002de8200b31f2657cc.jpg");
        mDataList.add("http://pkicdn.image.alimmdn.com/old/newuploads/2579cfef9f9fa1e22128243d92ff001a.jpg");
        mDataList.add("http://pkicdn.image.alimmdn.com/old/newuploads/7efc96106624cc602f3336d7f5c6f086.JPG");
        return view;
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        String url;
        ArrayList<String> urls = new ArrayList<>();
        switch (resultCode) {
            case Constant.CALLBACK_CODE_SELETE:
                urls = data.getExtras().getStringArrayList(Constant.CALLBACK_DATA_CODE);
                dumpLog("selected", urls);
                break;

            case Constant.CALLBACK_CODE_DELECT:
                urls = data.getExtras().getStringArrayList(Constant.CALLBACK_DATA_CODE);
                dumpLog("delete", urls);
                break;

            case Constant.CALLBACK_CODE_SAVE:
                urls = data.getExtras().getStringArrayList(Constant.CALLBACK_DATA_CODE);
                dumpLog("save", urls);
                break;
        }
    }

    private void dumpLog(String action, ArrayList<String> urls) {
        if (urls != null && urls.size() > 0) {
            for (String url1 : urls) {
                Log.d(TAG, action + " url == " + url1);
            }
        } else {
            Log.d(TAG, action + " no url");
        }
    }


    @OnClick({R.id.btn_select, R.id.btn_delete, R.id.btn_save})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_select:
                PictureBrowserActivity.watchPhoto(this, mDataList, Constant.RESULT_CODE_SELETE);
                break;
            case R.id.btn_delete:
                PictureBrowserActivity.watchPhoto(this, mDataList, Constant.RESULT_CODE_DELETE);
                break;
            case R.id.btn_save:
                PictureBrowserActivity.watchPhoto(this, mDataList, Constant.RESULT_CODE_SAVE);
                break;
        }
    }


}
